﻿var MID
var sUserID
var tree
$(function(){
  MID= queryString("MID");
  sUserID= queryString("sUserID");
  mini.parse();
  //var tree = mini.get("tree1");
  //tree.load("../../../disPatchJson?clazz=READDATA&UITYPE=USER_MUTI_SELECT&sUserID="+sUserID)
  tree_show() 
 })
function tree_show(){
	var tempstr=window.top.getPama("TEMP_JSRJSON")
	if(tempstr!=""){
		var oJson=eval(tempstr)
	    //alert(mini.encode(oJson))
	    tree = mini.get("tree1");
		tree.loadData(oJson)
		return
	}
		$.post("../../../disPatchJson?clazz=READDATA&UITYPE=USER_MUTI_SELECT&sUserID="+sUserID, {},
        function (doc, textStatus){
				if (doc != null){
					    //alert(doc)
					    var oJson=eval(doc)
					    //alert(mini.encode(oJson))
					    tree = mini.get("tree1");
						tree.loadData(oJson)
				}
				else{
					alert("请求数据错误！")
				}
			})//
  }
function GetCheckedNodes() {
        var nodes = tree.getCheckedNodes();
        return nodes;
    }
    function GetData() {
        var nodes = tree.getCheckedNodes();
        var ids = [], texts = [];
        for (var i = 0, l = nodes.length; i < l; i++) {
            var node = nodes[i];
            ids.push(node.id);
            texts.push(node.text);
        }
        var data = {};
        data.id = ids.join(",");
        data.text = texts.join(",");
        return data;
    }
    function GetDataJson() {
    	return mini.encode(tree.data)
    }
    function search() {
        var key = mini.get("key").getValue();
        //grid.load({ key: key });
    }
    function onKeyEnter(e) {
        search();
    }
    //////////////////////////////////
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function onOk() {
        var node = tree.getSelectedNode();
        if (node && tree.isLeaf(node) == false) {
            alert("不能选中父节点");
            return;
        }
        
        CloseWindow("ok");
    }
    function onCancel() {
        CloseWindow("cancel");
    }
